package com.fly.demo.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.Assert;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fly.demo.entity.User;
import com.fly.demo.mapper.UserDao;
import com.fly.demo.service.UserService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 00fly
 * @since 2018-09-11
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService
{
    
    /**
     * 测试事务
     */
    @Override
    public void testTrans()
    {
        for (int i = 0; i < 10; i++)
        {
            User user = new User();
            user.setUsername("username" + i);
            user.setPassword("password" + i);
            user.setName("name" + i);
            user.setEnabled(true);
            user.setAge(18 + i);
            user.setCreateDate(new Date());
            save(user);
        }
        Assert.assertTrue(false);
    }
    
    /**
     * 批量插入
     */
    @Override
    public void testBatch()
    {
        List<User> users = new ArrayList<User>();
        for (int i = 0; i < 10; i++)
        {
            User user = new User();
            user.setUsername("username" + i);
            user.setPassword("password" + i);
            user.setName("name" + i);
            user.setEnabled(true);
            user.setAge(18 + i);
            user.setCreateDate(new Date());
            users.add(user);
        }
        saveBatch(users);
    }
    
}
